package com.nhjf.service.impl.teachers;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nhjf.command.comment.CreateCoursesCommentCommand;
import com.nhjf.dao.teachers.CoursesCommentDao;
import com.nhjf.model.system.User;
import com.nhjf.model.teachers.CoursesComment;
import com.nhjf.pojo.dto.result.ServiceResultDto;
import com.nhjf.pojo.qo.teachers.CoursesCommentQo;
import com.nhjf.service.impl.BaseServiceImpl;
import com.nhjf.service.teachers.CoursesCommentService;
@Transactional
@Service("coursesCommentService")
public class CoursesCommentServiceImpl extends BaseServiceImpl<CoursesComment, CoursesCommentQo,CoursesCommentDao> implements CoursesCommentService{
	
	@Autowired
	private CoursesCommentDao coursesCommentDao;
	
	@Override
	protected CoursesCommentDao getDao() {
		// TODO Auto-generated method stub
		return coursesCommentDao;
	}

	@Override
	public ServiceResultDto createCoursesComment(CreateCoursesCommentCommand createCoursesCommentCommand) {
		// TODO Auto-generated method stub
		
		ServiceResultDto resultDto = new ServiceResultDto();
		CoursesComment coursesComment=new CoursesComment();
		if(StringUtils.isEmpty(createCoursesCommentCommand.getComment())) {
			resultDto.setSuccess(false);
			resultDto.setResultMessage("评论内容为空");
		}
		coursesComment.setComment(createCoursesCommentCommand.getComment());
		coursesComment.setCommentTime(new Date());
		coursesComment.setCommentType(createCoursesCommentCommand.getCommentType());
		coursesComment.setCommentUserType(createCoursesCommentCommand.getCommentUserType());
		coursesComment.setCoursesId(createCoursesCommentCommand.getCoursesId());
		User user=new User();
		user.setId(createCoursesCommentCommand.getUserId());
		coursesComment.setUser(user);
		coursesCommentDao.save(coursesComment);
		resultDto.setSuccess(true);
		resultDto.setResultMessage("评论成功");
		return resultDto;
	}

}
